package com.example.backendmanage.mapper;

import com.example.backendmanage.info.Menu;
import com.example.backendmanage.info.MenuRole;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MenuMapper {
    @Select("select * from sys_menu")
    List<Menu> findAll();
    @Insert("insert into sys_menu(name,path,icon,description,pid) values(#{name},#{path},#{icon},#{description},#{pid})")
    int addMenu(Menu menu);

    @Delete("delete from sys_role_menu where roleId = #{roleId}")
    int deleteMR(Integer roleId);

    @Insert("insert into sys_role_menu(roleId,menuId) values(#{roleId},#{menuId})")
    int addMR(MenuRole menuRole);

    @Select("select menuId from sys_role_menu where roleId = #{roleId}")
    List<Integer> selectMenuByRoleId(Integer roleId);

    @Select("select id from sys_role where role_key=#{role_key}")
    Integer selectRoleIdByRole(String role_key);

    @Select("select * from sys_menu where id=#{id}")
    Menu selectMenuByMenuId(Integer id);

    @Select("select pid from sys_menu where id = #{id}")
    Integer getPid(Integer id);

    @Select("select count(*) from sys_role_menu where roleId = #{roleId} and menuId=#{menuId}")
    Integer checkPidExist(Integer roleId,Integer menuId);

    @Insert("insert into sys_role_menu(roleId,menuId) values(#{roleId},#{menuId})")
    Integer addLostMenuRole(Integer roleId,Integer menuId);
}
